package com.itheima.sh.filterlogin;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//1. 登录之后：能够访问hack.html，然后下载黑客视频资源，成为NB黑客；
//2. 未登录：跳转到登录页面，并提示"请先登录"；
//3. 我们对hack.html页面进行过滤，
@WebServlet("/loginServlet")
public class loginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //2.姓名密码封装在user对象
        User user=new User(username,password);
         //3把user放在session对象里传输
         request.getSession().setAttribute("user",user);
         //4响应，并跳转到hack.html
         response.sendRedirect("/hack.html");


    }
}